<template>
    <div>
        <table border="1">
            <tbody>
                <tr>
                    <th>Id</th>
                    <th>
                        <input type="text" v-model="data.Id">
                    </th>
                </tr>
                <tr>
                    <th>门店编号</th>
                    <th>
                        <input type="text" v-model="data.Num">
                    </th>
                </tr>
                <tr>
                    <th>门店名称</th>
                    <th>
                        <input type="text" v-model="data.Name">
                    </th>
                </tr>
                <tr>
                    <th>门店业态</th>
                    <th>
                        <input type="text" v-model="data.YT">
                    </th>
                </tr>
                <tr>
                    <th>状态</th>
                    <th>
                        <input v-model="data.State" type="radio" name="State" value="true">开店
                        <input v-model="data.State" type="radio" name="State" value="false">闭店
                    </th>
                </tr>
                <tr>
                    <th>开店日期</th>
                    <th>
                        <input type="date" v-model="data.CreateTime">
                    </th>
                </tr>
                <tr>
                    <th>门店电话</th>
                    <th>
                        <input type="text" v-model="data.Phone">
                    </th>
                </tr>
                <tr>
                    <th>店长</th>
                    <th>
                        <input type="text" v-model="data.DZ">
                    </th>
                </tr>
                <tr>
                    <th>店长电话</th>
                    <th>
                        <input type="text" v-model="data.DZPhone">
                    </th>
                </tr>
                <tr>
                    <th>图片</th>
                    <th>
                        <input type="file" @change="UpLoad"> 
                        <img :src="'https://localhost:7212/'+data.Img" style="width: 100px; height: 100px;" >
                    </th>
                </tr>
                <tr>
                    <th>
                        <input type="button" value="修改" @click="Up">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
import moment from 'moment';
import { useRouter } from 'vue-router';
const data=ref({
    "Id": 0,
  "Num": "",
  "Name": "",
  "YT": "",
  "State": true,
  "CreateTime": "",
  "Phone": "",
  "DZ": "",
  "DZPhone": "",
  "Delete": true,
  "Img": ""
})

onMounted(()=>{
    DetailMember();
})

const route=useRoute();

const DetailMember=()=>{
    var val=route.query.Id;
    axios.get("https://localhost:7212/api/Member/Detail",{params:{Id:val}}).then(res=>{
        data.value=res.data;
        data.value.CreateTime=moment(data.value.CreateTime).format("YYYY-MM-DD")
    })
}


const UpLoad=(e:any)=>{
    var f=e.target.files[0];
    var fd=new FormData();

    fd.append("file",f);

    if(f.size>1024*1024*2){
        alert('图片不能超过1mb')
        return;
    }
    if(f.type!="image/jpeg" && f.type!="image/png"){
        alert('格式不正确');
        return;
    }

    axios.post("https://localhost:7212/api/UpLoad/Up",fd).then(res=>{
        data.value.Img=res.data;
    })

}

const rou=useRouter();


const Up=()=>{
    axios.put("https://localhost:7212/api/Member/UpdateMember",data.value).then(res=>{
        if(res.data>0){
            alert('修改成功')
            rou.push({path:"/"})
        }
        else{
            alert('修改失败')
        }
    })
}


</script>

